package com.haynes.social.common;

/**
 * 设置线程中的用户id
 * @Author Haynes
 * @Date 2023/5/26 15:46
 * @PackageName:com.haynes.store.common
 * @ClassName: BaseContext
 */
public class BaseContext {
    private static final ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    /**
     * 在线程中添加用户的id
     * @param uid 当前用户id
     */
    public void setUid(Long uid){
        threadLocal.set(uid);
    }

    /**
     * 从线程中获取当前登录用户的id
     * @return 当前用户id
     */
    public Long getUid(){
        return threadLocal.get();
    }

    /**
     * 从线程中删除当前登录用户的id
     */
    public void removeUid(){
        threadLocal.remove();
    }
}
